﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Media;
using System.Xml;
using System.Xml.Linq;

using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Frames;
using Styx.CommonBot.Profiles;
using Styx.Helpers;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;

namespace TheAnimus
{
	public partial class AnimusUI : Form
	{
		public int lastUseProfile = 0;
		public string pathToProfiles = Path.Combine(Utilities.AssemblyDirectory + @"\Default Profiles\TheAnimus\");
		public string profileToLoad = "";
		
		public AnimusUI()
		{
            this.BackgroundImage = new Bitmap(Application.StartupPath + "\\Plugins\\TheAnimus\\Images\\WorldMap-World_Blue.jpg");
			InitializeComponent();
		}

		private void AnimusUI_Load(object sender, EventArgs e)
		{

		}
		
		private void ProfileSelector()
		{
			if (lastUseProfile == null || lastUseProfile == 0)
				return;

			// Questing Profiles
			if (lastUseProfile == 1) { loadProfile(pathToProfiles + "EKMemBlock [Brodie].xml"); }
			if (lastUseProfile == 2) { loadProfile(pathToProfiles + "KalimdorMemBlock [Brodie].xml"); }
		}
		
		private void loadProfile(string ProfileToLoad)
		{
			bool isRunning = TreeRoot.IsRunning;
			if (isRunning)
				Close();
				
			else
			{
				var questBot = BotManager.Instance.Bots.FirstOrDefault(kvp => kvp.Key == "Questing");
				if (questBot.Key == "Questing")
					BotManager.Instance.SetCurrent(questBot.Value);
				else
					Logging.Write("Unable to locate Questing bot");
			}
			Styx.CommonBot.Profiles.ProfileManager.LoadNew(ProfileToLoad);
			Close();
			TreeRoot.Start();
		}

		private void pictureBoxEK_Click(object sender, EventArgs e)
		{
            if (StyxWoW.Me.Level >= 60)
            {
                var dialogResult = MessageBox.Show
                    ("You have selected the Eastern Kingdoms Memory Block. This will revisit all incomplete areas on this continent.", "EK Mem Block",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);

                if (dialogResult == DialogResult.Yes)
                {
                    lastUseProfile = 1; // Do Eastern Kingdoms
                    ProfileSelector();
                }
            }
            else
            {
                var dialogResult = MessageBox.Show
                    ("You have selected the Eastern Kingdoms Memory Block, but you are not yet of the minimum required level (60).", "EK Mem Block",
                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
		}

		private void pictureBoxKalim_Click(object sender, EventArgs e)
		{
            if (StyxWoW.Me.Level >= 60)
            {
                var dialogResult = MessageBox.Show
                    ("You have selected the Kalimdor Memory Block. This will revisit all incomplete areas on this continent.", "Kalimdor Mem Block",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);

                if (dialogResult == DialogResult.Yes)
                {
                    lastUseProfile = 2; // Do Kalimdor
                    ProfileSelector();
                }
            }
            else
            {
                var dialogResult = MessageBox.Show
                    ("You have selected the Kalimdor Memory Block, but you are not yet of the minimum required level (60).", "Kalimdor Mem Block",
                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
		}

        private void pictureBoxKalim_MouseEnter(object sender, EventArgs e)
        {
            if (StyxWoW.Me.Level < 60)
                this.BackgroundImage = new Bitmap(Application.StartupPath + "\\Plugins\\TheAnimus\\Images\\kalimdor_red.jpg");
            if (StyxWoW.Me.Level >= 60)
                this.BackgroundImage = new Bitmap(Application.StartupPath + "\\Plugins\\TheAnimus\\Images\\kalimdor_color.jpg");
        }

        private void pictureBoxKalim_MouseLeave(object sender, EventArgs e)
        {
            this.BackgroundImage = new Bitmap(Application.StartupPath + "\\Plugins\\TheAnimus\\Images\\WorldMap-World_Blue.jpg");
        }

        private void pictureboxEK_MouseEnter(object sender, EventArgs e)
        {
            if (StyxWoW.Me.Level < 60)
                this.BackgroundImage = new Bitmap(Application.StartupPath + "\\Plugins\\TheAnimus\\Images\\EK_red.jpg");
            if (StyxWoW.Me.Level >= 60)
                this.BackgroundImage = new Bitmap(Application.StartupPath + "\\Plugins\\TheAnimus\\Images\\EK_color.jpg");
        }

        private void pictureboxEK_MouseLeave(object sender, EventArgs e)
        {
            this.BackgroundImage = new Bitmap(Application.StartupPath + "\\Plugins\\TheAnimus\\Images\\WorldMap-World_Blue.jpg");
        }
	}
}
